######################### AGGREGATE REGRESSION ANALYSIS ############################
####################################################################################
#Name of code file: regression_analysis.R
#Purpose: Regression Models for Aggregate Data
#Data In: network_tolerance_processed_data.csv
#Data Out: Figures: 5 Tables: A5-A10
####################################################################################
#Load packages
library(readr)
library(coefplot)
library(apsrtable)
library(MASS)
library(AER)
library(ggplot2)
library(estout)
library(interplot)
library(xtable)
#Set Working Directory
setwd("~/Dropbox/egypt_tolerance_wp_replication/")
#Read in Data
data<-read_csv("data/network_tolerance_processed_data.csv")
thresholds<-read_csv("data/thresholds.csv")
#Name of code file: regression_analysis.R
#Purpose: Regression Models for Aggregate Data
#Data In: network_tolerance_processed_data.csv
#Data Out: Figures: 5 Tables: A5-A10
####################################################################################
#Load packages
library(readr)
library(coefplot)
library(apsrtable)
library(MASS)
library(AER)
library(ggplot2)
library(estout)
library(interplot)
library(xtable)
#Set Working Directory
setwd("~/Dropbox/egypt_tolerance_wp_replication/")
#Read in Data
data<-read_csv("data/network_tolerance_processed_data.csv")
thresholds<-read_csv("data/thresholds.csv")
##########
#TABLE A5#
##########
#Quasi Poisson Intolerant Count Model
quasipoisson_intolerant_model <- glm(data$intolerant_total ~ data$elite_diversity + data$nonelite_diversity +data$log_total_friends +data$log_elite+ data$log_relevant_tweets + data$log_time +  data$islamist, family=quasipoisson())
summary(quasipoisson_intolerant_model)
exp_quasi<-as.data.frame(exp(coef(quasipoisson_intolerant_model)))
xtable(exp_quasi)
#Run Without Controls
quasipoisson_intolerant_model_no_cont <- glm(data$intolerant_total ~ data$elite_diversity + data$nonelite_diversity , family=quasipoisson())
summary(quasipoisson_intolerant_model_no_cont)
#Proportion Intolerant OLS Model
prop_intolerant_model <- lm(data$prop_intolerant ~ data$elite_diversity + data$nonelite_diversity +data$log_total_friends +data$log_elite+ data$log_relevant_tweets+ data$log_time + data$islamist)
summary(prop_intolerant_model)
#Run Without Controls
prop_intolerant_model_no_cont <- lm(data$prop_intolerant ~ data$elite_diversity + data$nonelite_diversity)
summary(prop_intolerant_model_no_cont)
#Make Table
apsrtable(quasipoisson_intolerant_model_no_cont, quasipoisson_intolerant_model, prop_intolerant_model_no_cont, prop_intolerant_model, digits=4, lev=.1, stars="default")
